# 字典

# 定义

# dic = {"健": "值"}

dic = {
    "name": "张三",
    "age": 21,
    "gender": "男"
}

# 特性
# 无序的
# 可变的
# 健不可重复，必须是不可变的数据类型
# 值任意的

# 增删改查
# 增

dic["class"] = "rg-2301"

# print(dic)

dic.update({"hobbies": ["唱", "跳", "rap"]})

print(dic)


# 删
# del dic["gender"]
#
# print(dic)

hobbies = dic.pop("hobbies")      # 弹出具体某个键值对，返回对应的值
print(hobbies)
print(dic)


# 改
# 与增加一样

dic["age"] = 23

dic.update({"class": "2301"})


dic["score"] = 23

print(dic)


# 查询

# print(
#     dic["hobbies"]
# )

# print(
#     dic.get('hobbies', "没有")
# )


# 内置函数

# 遍历字典的健
dic.keys()  # 可迭代对象

dic_scores = {
    "张三": 90.5,
    "李四": 91,
    "王五": 89.2,
    "赵六": 59,
}

# 假设最高分、最低分、还有平均分
max_score = 0
min_score = 100
total_score = 0

for key in dic_scores.keys():
    score = float(dic_scores.get(key))

    if score > max_score:
        max_score = score

    if score < min_score:
        min_score = score

    total_score += score

# print("最大值：", max_score)
# print("最小值：", min_score)
# print("平均分：", total_score / len(dic_scores))

# 遍历字典的值
# dic_scores.values()    # 可迭代对象
#
# for value in dic_scores.values():
#     print(value)


# 遍历字典的键值对

max_score_name = ''
min_score_name = ''

max_score = 0
min_score = 100

for key, value in dic_scores.items():       # 获取字典的键值对的固定写法
    # print(f"健：{key}； 值：{value}")

    if value > max_score:
        max_score = value
        max_score_name = key

    if value < min_score:
        min_score = value
        min_score_name = key


# print("最高分是：", max_score_name)
# print("最低分是：", min_score_name)


# 字典的嵌套

dic3 = {"class-2301": dic_scores, "class-2302": dic_scores}
print(dic3)
